﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Disassembler
{
    class FileReaderClass : Reader
    {
        private string _dataFromFile;
        private string _codeFromFile;
        private CodeReaderClass _codeReader;

        public FileReaderClass(string pathToData)
            : base(pathToData)
        {
        }

        public string ReadDissasmTables()
        {
            if (File.Exists(DisassmStruct.PathToSctruct))
            {
                _dataFromFile = File.ReadAllBytes(PathToData).ToString();
                _codeFromFile = ReadCode();
                return _codeFromFile;
            }
            else
            {
                throw new Exception("FileReaderClass - ReadDissasmTables - file does not exists " + DisassmStruct.PathToSctruct);
            }

            try
            {
                if (!DisassmStruct.LoadDisassmTables())
                    throw new Exception("Dont' loaded DisassmTables");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }

            _dataFromFile = File.ReadAllBytes(PathToData).ToString();
            return _dataFromFile;
        }

        public string ReadData()
        {
            if (PathToData.LastIndexOf(".exe") == null)
            {
                throw new Exception(PathToData + " bad file, use .exe");
            }

            _dataFromFile = File.ReadAllText(PathToData);
            return _dataFromFile;
        }

        private string ReadCode()
        {
            //!
            //_codeFromFile = _codeReader.();
            throw new Exception("FileReaderClass - ReadCode does not implement");
            //return _codeFromFile;
        }
    }
}
